#include <rtthread.h>
#include <stdio.h>

#include <qmc5883l.h>

#define QMC_I2C ":dev/i2c1"

static int qmc(int argc, char **argv)
{
    qmc5883l q;
    int cnt = 5;
    char *devnm = QMC_I2C;

    if (argc == 2)
        devnm = argv[1];

    if (!q.open(devnm))
    {
        printf("open fail\r\n");
        return -1;
    }

    if (!q.init())
    {
        q.close();
        printf("init fail\r\n");
        return -1;
    }

    while (cnt-- > 0)
    {
        short x, y, z;

        if (!q.readMag(x, y, z))
        {
            printf("read fail\r\n");
            break;
        }

        printf("x[%d] y[%d] z[%d]\r\n", x, y, z);
    }

    return 0;
}
MSH_CMD_EXPORT(qmc, test qmc5883l);
